package de.tt.user.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import de.tt.user.dto.UserDTO;

public class RegisterServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4794487386364261525L;

	// private static final Logger log = Logger.getLogger(RegisterServlet.class
	// .getName());

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		UserDTO userDTO = applyRequestValues(req);

		// if (!processValidations(status)) {
		// resp.getWriter().println(new XStream().toXML(status));
		// return;
		// }

		// getUser().setConfirmKey(new UserSupport().generateConfirmKey());
		//
		// User savedUser = new UserDAO().save(getUser());
		// if (savedUser == null) {
		// status.setMain("Internal Error: Bitte versuchen Sie noch einmal!");
		// resp.getWriter().println(new XStream().toXML(status));
		// return;
		// }
		//
		// new EmailService().sendAccountConfirmEmail(savedUser,
		// getServletContext());
		// String accConfirm = new FileService().readFile(getServletContext(),
		// HTMLPage.ACCOUNT_CONFIRM);
		// String userMailAccount = savedUser.getEmail();
		// int atEndex = userMailAccount.indexOf("@");
		// status.setMain(accConfirm.replace("#{email}", savedUser.getEmail())
		// .replace("#{userMailAccount}",
		// userMailAccount.substring(atEndex + 1)));
		// resp.getWriter().println(new XStream().toXML(status));
	}

	// private boolean processValidations(StatusXML status) {
	// return (new Validator()).validateRegisterInput(getUser(), status);
	// }

	private UserDTO applyRequestValues(HttpServletRequest req) {
		UserDTO userDTO = new UserDTO();
		userDTO.setEmail(req.getParameter("email"));
		userDTO.setEmailRepeat(req.getParameter("email_repeat"));
		userDTO.setPassword(req.getParameter("password"));
		return userDTO;
	}
}
